/**
 * Created by ACER on 2018/1/27.
 */
app.controller("personal-information", function ($http, $scope) {
    //证书
    var token = localStorage.getItem('token');
    //用户信息对象
    $scope.userInfo = {};

    $scope.getUserInfo = function () {
        //判断有无证书
        if (!token) {
            $.toast('请先登录');
            location.href = '#login';
            return;
        }
        if (token) {
            $http({
                method: 'get',
                url: app.netPath + '/users/details/show',
                headers: {Authorization: token}
            }).then(function (res) {
                console.log(res);
                if (!res.data.error) {
                    $scope.userInfo = res.data.data;
                    var thisTime = new Date();
                    $scope.userInfo.userAge = parseInt((parseInt(thisTime.valueOf()) - parseInt($scope.userInfo.userBirthday).valueOf()) / (365 * 24 * 60 * 60 * 1000));
                    var avatarImg = {};

                    if (res.data.data.userAvatarAddress) {
                        avatarImg.imgAddress = app.netPath + '/resources/img/' + res.data.data.userAvatarAddress;
                        $scope.userInfo.avatarImg = avatarImg;
                    }
                }
            }, function () {
                $.toast('网络走丢了！')
            })
        }

    }
});